<template>
  <div class="settings">
    <van-nav-bar safe-area-inset-top placeholder :title="$t('AdvancedSetting')" left-arrow fixed @click-left="onClickLeft" />
    <van-pull-refresh v-model="isLoading" :pulling-text="$t('PullingText')" :loosing-text="$t('PullingText')" :success-text="$t('refreshSuccee')" @refresh="onRefresh">
      <van-collapse class="marginTop15" v-model="activeNames">
        <van-collapse-item :title="$t('Safety')" name="1">
          <safetyPTVue :deviceType="16" :safety="safety" :reg="5" :key="timer" @getFormData="setSafety"></safetyPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('ExportControl')" name="2">
          <languagePTVue
            :setName="$t('ExportControl')"
            :columns="ExportControlArr"
            :setValue="LocalArr.exportEnableCode"
            :reg="26"
            @getFormData="setExportEnable"
            ></languagePTVue>
          <pfLockInPointPTVue :setName="$t('UserValue')" :setUntil="'W'" :setMin="0" :setMax="60000" :setValue.sync="LocalArr.ExportLimitValue" :reg="12" v-if="isExportControl"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item title="DRM Function" name="3">
          <languagePTVue :columns="toggleArr" :setValue="LocalArr.DRMFunctionValue" :reg="61"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('RS485Address')" name="4">
          <pfLockInPointPTVue :setMin="1" :setMax="255" :setValue.sync="LocalArr.RS485AddressValue" :reg="59"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('MpptScanMode2')" name="5">
          <languagePTVue :columns="MpptArr" :setValue="LocalArr.MpptScanModeValue" :reg="60"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item title="P(freq)" name="6">
          <languagePTVue
            :setName="$t('POverfreq')"
            :columns="toggleArr"
            :setValue="LocalArr.POverfreqCode"
            :reg="44"
            @getFormData="setPOverfreqEnable"
          ></languagePTVue>
          <div v-if="isPOverfreq">
            <languagePT3Vue
              :setName="$t('CurveType')"
              :columns="CurveTypeArr"
              :setValue="LocalArr.CurveTypeValue"
              :reg="75"
              @getFormData="setCurveType"
            ></languagePT3Vue>
            <facMaxPTVue :setName="$t('FreqOverPoint')" :setUntil="'Hz'" :setMin="'50.20'" :setMax="'50.50'" :setValue.sync="LocalArr.wFreqSetPointValue" :reg="45"></facMaxPTVue>
            <vacMaxPTVue :setName="$t('RPBF_DroopRate')" :setUntil="'%'" :setMin="'2.0'" :setMax="'12.0'" :setValue.sync="LocalArr.wFreqDroopRateValue" :reg="46"></vacMaxPTVue>
            <facMaxPTVue :setName="$t('EntryDelayTime')" :setUntil="'S'" :setMin="'0.00'" :setMax="'60.00'" :setValue.sync="LocalArr.EntryDelayTimeValue" :reg="76"></facMaxPTVue>
            <facMaxPTVue :setName="$t('ExitDelayTime')" :setUntil="'S'" :setMin="'0.00'" :setMax="'60.00'" :setValue.sync="LocalArr.ExitDelayTimeValue" :reg="77"></facMaxPTVue>
            <facMaxPTVue :setName="$t('FreqStopPoint')" :setUntil="'Hz'" :setMin="'45.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FreqStopPointValue" :reg="78" v-if="isCurveType"></facMaxPTVue>
          </div>
          <languagePTVue
            :setName="$t('PUnderfreq')"
            :columns="toggleArr"
            :setValue="LocalArr.PUnderfreqCode"
            :reg="47"
            @getFormData="setPUnderfreqEnable"
          ></languagePTVue>
          <div v-if="isPUnderfreq">
            <facMaxPTVue :setName="$t('FreqUnderPoint')" :setUntil="'Hz'" :setMin="'45.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FreqUnderPointValue" :reg="48"></facMaxPTVue>
            <vacMaxPTVue :setName="$t('IPBF_DroopRate')" :setUntil="'%'" :setMin="'2.0'" :setMax="'12.0'" :setValue.sync="LocalArr.FreqUnderRampValue" :reg="49"></vacMaxPTVue>
            <facMaxPTVue :setName="$t('EntryDelayTime')" :setUntil="'S'" :setMin="'0.00'" :setMax="'60.00'" :setValue.sync="LocalArr.IPBFEntryDelayTimeValue" :reg="79"></facMaxPTVue>
          </div>
        </van-collapse-item>
        <van-collapse-item :title="$t('SoftStart')" name="7">
          <languagePTVue
            :columns="toggleArr"
            :setValue="LocalArr.softStartEnableCode"
            :reg="50"
            @getFormData="setSoftStart"
          ></languagePTVue>
          <vacMaxPTVue :setName="$t('SoftStartSlope')" :setUntil="'%'" :setMin="'0.0'" :setMax="'100.0'" :setValue.sync="LocalArr.SoftStartSlopeValue" :reg="51" v-if="isSoftStart"></vacMaxPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('ReactivePower')" name="8">
          <van-form @submit="powerfactorSubmit">
            <van-field
              :value="LocalArr.factMode"
              :label="$t('ModeSelect')"
              readonly
              clickable
              name="picker"
              input-align="right"
              @click="showPowerFact = true"
            />
            <van-popup v-model="showPowerFact" round position="bottom">
              <van-picker
                show-toolbar
                :columns="powerFactors"
                @cancel="showPowerFact = false"
                @confirm="factModeConfirm"
                :confirm-button-text="$t('OK')"
                :cancel-button-text="$t('Cancel')" 
              />
            </van-popup>
            <van-field v-if="factModeCode==1||factModeCode==2"
              v-model="LocalArr.P2Value"
              :label="$t('PFValue')"
              type="number"
              show-error
              name="validator"
              input-align="right"
              error-message-align="right"
              clearable
              :rules="[{ validator:fixedTwo2,message: `${$t('Range')}：0.90-1.00` }]"
            />
            <van-field v-if="factModeCode==3"
              v-model="LocalArr.P3Value"
              :label="$t('PowerFactor1')"
              type="number"
              show-error
              name="validator"
              input-align="right"
              error-message-align="right"
              clearable
              :rules="[{ validator:fixedTwo1,message: `${$t('Range')}：0.80-1.00` }]"
            />
            <van-field v-if="factModeCode==3"
              v-model="LocalArr.P4Value"
              :label="$t('PowerFactor2')"
              type="number"
              show-error
              name="validator"
              input-align="right"
              error-message-align="right"
              clearable
              :rules="[{ validator:fixedTwo1,message: `${$t('Range')}：0.80-1.00` }]"
            />
            <van-field v-if="factModeCode==3"
              v-model="LocalArr.P5Value"
              label="PowerFactor3"
              type="number"
              show-error
              name="validator"
              input-align="right"
              error-message-align="right"
              clearable
              :rules="[{ validator:fixedTwo1,message: `${$t('Range')}：0.80-1.00` }]"
            />
            <van-field v-if="factModeCode==3"
              v-model="LocalArr.P6Value"
              label="PowerFactor4"
              type="number"
              show-error
              name="validator"
              input-align="right"
              error-message-align="right"
              clearable
              :rules="[{ validator:fixedTwo1,message: `${$t('Range')}：0.80-1.00` }]"
            />
            <div class="factorBtnBox">
              <van-button block round>{{$t('Save')}}</van-button>
            </div>
          </van-form>
          <vacMaxPTVue :setName="'PowerRatio1'" :setUntil="'%'" :setMin="'0.0'" :setMax="'100.0'" :setValue.sync="LocalArr.PowerRatio1Value" :reg="92" v-if="isPFP"></vacMaxPTVue>
          <vacMaxPTVue :setName="'PowerRatio2'" :setUntil="'%'" :setMin="'0.0'" :setMax="'100.0'" :setValue.sync="LocalArr.PowerRatio2Value" :reg="93" v-if="isPFP"></vacMaxPTVue>
          <vacMaxPTVue :setName="'PowerRatio3'" :setUntil="'%'" :setMin="'0.0'" :setMax="'100.0'" :setValue.sync="LocalArr.PowerRatio3Value" :reg="94" v-if="isPFP"></vacMaxPTVue>
          <vacMaxPTVue :setName="'PowerRatio4'" :setUntil="'%'" :setMin="'0.0'" :setMax="'100.0'" :setValue.sync="LocalArr.PowerRatio4Value" :reg="95" v-if="isPFP"></vacMaxPTVue>
          <vacMaxPTVue :setName="'EntryVolt'" :setUntil="'V'" :setMin="'10.0'" :setMax="'30.0'" :setValue.sync="LocalArr.PfLockInPointValue" :reg="22" v-if="isPFP"></vacMaxPTVue>
          <vacMaxPTVue :setName="'ExitVolt'" :setUntil="'V'" :setMin="'10.0'" :setMax="'30.0'" :setValue.sync="LocalArr.PfLockOutPointValue" :reg="23" v-if="isPFP"></vacMaxPTVue>
          <languagePTVue :setName="'QPowerLockEn'" :columns="toggleArr" :setValue="LocalArr.QPowerLockEnValue" :reg="84" v-if="isQu"></languagePTVue>
          <vacMaxPTVue :setName="'QuLockIn'" :setUntil="'%'" :setMin="'2.0'" :setMax="'12.0'" :setValue.sync="LocalArr.QuLockInValue" :reg="85" v-if="isQu"></vacMaxPTVue>
          <vacMaxPTVue :setName="'QuLockOut'" :setUntil="'%'" :setMin="'2.0'" :setMax="'12.0'" :setValue.sync="LocalArr.QuLockOutValue" :reg="86" v-if="isQu"></vacMaxPTVue>
          <vacMaxPTVue :setName="'QuGridV1'" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.QuGridV1Value" :reg="87" v-if="isQu"></vacMaxPTVue>
          <vacMaxPTVue :setName="'QuGridV2'" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.QuGridV2Value" :reg="88" v-if="isQu"></vacMaxPTVue>
          <vacMaxPTVue :setName="'QuGridV3'" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.QuGridV3Value" :reg="89" v-if="isQu"></vacMaxPTVue>
          <vacMaxPTVue :setName="'QuGridV4'" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.QuGridV4Value" :reg="90" v-if="isQu"></vacMaxPTVue>
          <pfLockInPointPT2Vue :setName="$t('bQpower_set')" :setUntil="'Var'" :setMin="-30000" :setMax="30000" :setValue.sync="LocalArr.bQpower_setValue" :reg="55" v-if="isQSet"></pfLockInPointPT2Vue>
        </van-collapse-item>
        <van-collapse-item :title="$t('puFunction')" name="9">
          <languagePTVue
            :setName="$t('puFunction')"
            :columns="toggleArr"
            :setValue="LocalArr.puFunctionEnableCode"
            :reg="52"
            @getFormData="setPuFunction"
          ></languagePTVue>
          <vacMaxPTVue :setName="$t('Pu_GridV1')" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.SetV1Value" :reg="80" v-if="isPu"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('Pu_GridV2')" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.SetV2Value" :reg="81" v-if="isPu"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('Pu_GridV3')" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.SetV3Value" :reg="82" v-if="isPu"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('Pu_GridV4')" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.SetV4Value" :reg="83" v-if="isPu"></vacMaxPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('ActivePowerLimit')" name="10">
          <pfLockInPointPTVue :setUntil="'%'" :setMin="0" :setMax="100" :setValue.sync="LocalArr.ActivePowerLimitValue" :reg="56"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('GridProtection')" name="11">
          <vacMaxPTVue :setName="$t('OVStage1')" :setUntil="'V'" :setMin="'92.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMaxValue" :reg="27"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('OVStage2')" :setUntil="'V'" :setMin="'92.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMaxSlowProtectValue" :reg="28"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('OVStage3')" :setUntil="'V'" :setMin="'92.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMiddleSlowProtectValue" :reg="29"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('UVStage1')" :setUntil="'V'" :setMin="'92.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMinValue" :reg="30"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('UVStage2')" :setUntil="'V'" :setMin="'92.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMinSlowProtectValue" :reg="31"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('UVStage3')" :setUntil="'V'" :setMin="'92.0'" :setMax="'300.0'" :setValue.sync="LocalArr.UVStage3Value" :reg="32"></vacMaxPTVue>
          <languagePTVue :setName="$t('OV10MinAvgEnable')" :columns="toggleArr" :setValue="LocalArr.OV10EnableValue" :reg="33"></languagePTVue>
          <vacMaxPTVue :setName="$t('OV10minset')" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.Grid10MinAverageValue" :reg="34"></vacMaxPTVue>
          <facMaxPTVue :setName="$t('OFStage1')" :setUntil="'Hz'" :setMin="'45.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FacMaxValue" :reg="35"></facMaxPTVue>
          <facMaxPTVue :setName="$t('OFStage2')" :setUntil="'Hz'" :setMin="'45.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FacMaxSlowProtectValue" :reg="36"></facMaxPTVue>
          <facMaxPTVue :setName="$t('UFStage1')" :setUntil="'Hz'" :setMin="'45.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FacMinValue" :reg="37"></facMaxPTVue>
          <facMaxPTVue :setName="$t('UFStage2')" :setUntil="'Hz'" :setMin="'45.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FacMinSlowProtectValue" :reg="38"></facMaxPTVue>
          <languagePTVue :setName="$t('FreqROCOF')" :columns="toggleArr" :setValue="LocalArr.FreqROCOFValue" :reg="39"></languagePTVue>
          <pfLockInPointPTVue :setName="'T_Start'" :setUntil="'S'" :setMin="15" :setMax="1000" :setValue.sync="LocalArr.TStartValue" :reg="43"></pfLockInPointPTVue>
          <languagePTVue
            :setName="$t('H/LVRTFunction')"
            :columns="toggleArr"
            :setValue="LocalArr.HLVRTFunctionValue"
            :reg="40"
            @getFormData="setHLVRTFunction"
          ></languagePTVue>
          <vacMaxPTVue :setName="$t('Frt_EntryVoltUp')" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.Frt_EntryVoltUpValue" :reg="41" v-if="isHLVRT"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('Frt_EntryVoltDn')" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.Frt_EntryVoltDnValue" :reg="42" v-if="isHLVRT"></vacMaxPTVue>
          <pfLockInPointPTVue :setName="$t('Qu_3Tau')" :setUntil="'S'" :setMin="0" :setMax="60" :setValue.sync="LocalArr.Qu_3TauValue" :reg="53"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('Pu_3Tau2')" :setUntil="'S'" :setMin="0" :setMax="60" :setValue.sync="LocalArr.Pu_3TauValue" :reg="54"></pfLockInPointPTVue>
          <facMaxPTVue :setName="$t('VacOvp1stTime')" :setUntil="'S'" :setMin="'0.00'" :setMax="'10.00'" :setValue.sync="LocalArr.VacOvp1stTimeValue" :reg="67"></facMaxPTVue>
          <facMaxPTVue :setName="$t('VacOvp2ndTime')" :setUntil="'S'" :setMin="'0.00'" :setMax="'10.00'" :setValue.sync="LocalArr.VacOvp2ndTimeValue" :reg="68"></facMaxPTVue>
          <facMaxPTVue :setName="$t('VacUvp1stTime')" :setUntil="'S'" :setMin="'0.00'" :setMax="'10.00'" :setValue.sync="LocalArr.VacUvp1stTimeValue" :reg="69"></facMaxPTVue>
          <facMaxPTVue :setName="$t('VacUvp2ndTime')" :setUntil="'S'" :setMin="'0.00'" :setMax="'10.00'" :setValue.sync="LocalArr.VacUvp2ndTimeValue" :reg="70"></facMaxPTVue>
          <facMaxPTVue :setName="$t('FacOfp1stTime')" :setUntil="'S'" :setMin="'0.00'" :setMax="'10.00'" :setValue.sync="LocalArr.FacOfp1stTimeValue" :reg="71"></facMaxPTVue>
          <facMaxPTVue :setName="$t('FacOfp2ndTime')" :setUntil="'S'" :setMin="'0.00'" :setMax="'10.00'" :setValue.sync="LocalArr.FacOfp2ndTimeValue" :reg="72"></facMaxPTVue>
          <facMaxPTVue :setName="$t('FacUfp1stTime')" :setUntil="'S'" :setMin="'0.00'" :setMax="'10.00'" :setValue.sync="LocalArr.FacUfp1stTimeValue" :reg="73"></facMaxPTVue>
          <facMaxPTVue :setName="$t('FacUfp2ndTime')" :setUntil="'S'" :setMin="'0.00'" :setMax="'10.00'" :setValue.sync="LocalArr.FacUfp2ndTimeValue" :reg="74"></facMaxPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('InverterStartStop')" name="12">
          <languagePTVue :columns="toggleArr" :setValue="LocalArr.InverterStartStopValue" :reg="62"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Reset')" name="13">
          <resetINVEnergyPTVue :setName="$t('ClearInverterHistory')" :reg="64"></resetINVEnergyPTVue>
          <resetINVEnergyPTVue :setName="$t('ResetErrorLogs')" :reg="63"></resetINVEnergyPTVue>
          <resetINVEnergyPTVue :setName="$t('ResetMeterEnergy')" :reg="65"></resetINVEnergyPTVue>
          <resetINVEnergyPTVue :setName="$t('ResetWIFI')" :reg="96"></resetINVEnergyPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('NewPassword')" name="14">
          <newPasswordPTVue :setValue.sync="LocalArr.NewPasswordValue" :reg="57"></newPasswordPTVue>
        </van-collapse-item>
        <van-collapse-item title="Self Test" name="15">
          <van-cell title="Self Test Start" is-link @click="goSelftTest(1)" />
          <van-cell title="Self Test Results" is-link @click="goSelftTest(2)" />
        </van-collapse-item>
      </van-collapse>
    </van-pull-refresh>
  </div>
</template>

<script>
import safetyPTVue from "../../../components/Safety/BDSafetyPT";
import pfLockInPointPTVue from "../../../components/PfLockInPoint/BDPfLockInPointPT";
import vacMaxPTVue from "../../../components/VacMax/BDVacMaxPT";
import languagePTVue from "../../../components/Language/BDLanguagePT";
import facMaxPTVue from "../../../components/FacMax/BDFacMaxPT";
import tripFreVue from "../../../components/TripFre/TripFre";
import resetINVEnergyPTVue from "../../../components/ResetINVEnergy/BDResetINVEnergyPT";
import newPasswordPTVue from "../../../components/NewPassword/BDNewPasswordPT";
import pfLockInPointPT2Vue from '../../../components/PfLockInPoint/BDPfLockInPoint2PT'
import languagePT3Vue from '../../../components/Language/BDLanguage3PT'

export default {
  components: {
    safetyPTVue,
    pfLockInPointPTVue,
    vacMaxPTVue,
    languagePTVue,
    facMaxPTVue,
    tripFreVue,
    resetINVEnergyPTVue,
    newPasswordPTVue,
    pfLockInPointPT2Vue,
    languagePT3Vue
  },
  data() {
    return {
      isLoading: false,
      timer: "",
      activeNames: [],
      safety: sessionStorage.getItem("safety"),
      showPowerFact: false,
      factorArr: [{text:this.$t('Off'),code:0},{text:this.$t('OverExcited'),code:1},{text:this.$t('UnderExcited'),code:2},{text:this.$t('PF(P)2'),code:3},{text:this.$t('Q(u)'),code:4},{text:this.$t('Q-Set'),code:5}],
      powerFactors: [],
      factModeCode: "",
      isPFP: true,
      isQu: true,
      isQSet: true,
      isExportControl: false,
      toggleArr: [this.$t('Disable'),this.$t('Enable')],
      isPu: false,
      isSoftStart: false,
      MpptArr:[this.$t('Off'),this.$t('LowFreqScan'),this.$t('MidFreqScan'),this.$t('HighFreqScan')],
      isPOverfreq:false,
      CurveTypeArr:[this.$t('f1Mode'),this.$t('fstopMode')],
      isPUnderfreq:false,
      isHLVRT:false,
      ExportControlArr:[this.$t('Disable'),'Meter'],
      isCurveType:false,
      LocalArr: {
        factMode: "",
        P2Value: "",
        P3Value: "",
        P4Value: "",
        P5Value: "",
        P6Value: "",
        PfLockInPointValue: "",
        PfLockOutPointValue: "",
        bQpower_setValue: "",
        VacMaxValue: "",
        VacMaxSlowProtectValue: "",
        VacMinValue: "",
        VacMinSlowProtectValue: "",
        OV10EnableValue: "",
        Grid10MinAverageValue: "",
        FacMaxValue: "",
        FacMaxSlowProtectValue: "",
        FacMinValue: "",
        FacMinSlowProtectValue: "",
        FreqROCOFValue: "",
        VacMiddleSlowProtectValue: "",
        TStartValue: "",
        HLVRTFunctionValue: "",
        exportEnableCode: "",
        ExportLimitValue: "",
        DRMFunctionValue: "",
        puFunctionEnableCode: "",
        SetV2Value: "",
        SetV3Value: "",
        SetV4Value: "",
        wFreqSetPointValue: "",
        wFreqDroopRateValue: "",
        softStartEnableCode: "",
        InverterStartStopValue: "",
        RS485AddressValue:'',
        MpptScanModeValue:'',
        POverfreqCode:'',
        CurveTypeValue:'',
        EntryDelayTimeValue:'',
        ExitDelayTimeValue:'',
        FreqStopPointValue:'',
        PUnderfreqCode:'',
        FreqUnderPointValue:'',
        FreqUnderRampValue:'',
        IPBFEntryDelayTimeValue:'',
        SoftStartSlopeValue:'',
        PowerRatio3Value:'',
        PowerRatio4Value:'',
        QPowerLockEnValue:'',
        QuLockInValue:'',
        QuLockOutValue:'',
        QuGridV1Value:'',
        QuGridV2Value:'',
        QuGridV3Value:'',
        QuGridV4Value:'',
        SetV1Value:'',
        ActivePowerLimitValue:'',
        UVStage3Value:'',
        Frt_EntryVoltUpValue:'',
        Frt_EntryVoltDnValue:'',
        Qu_3TauValue:'',
        Pu_3TauValue:'',
        VacOvp1stTimeValue:'',
        VacOvp2ndTimeValue:'',
        VacUvp1stTimeValue:'',
        VacUvp2ndTimeValue:'',
        FacOfp1stTimeValue:'',
        FacOfp2ndTimeValue:'',
        FacUfp1stTimeValue:'',
        FacUfp2ndTimeValue:'',
        PowerRatio1Value:'',
        PowerRatio2Value:'',
        NewPasswordValue: ""
      }
    };
  },
  methods: {
    onClickLeft() {
      this.$router.push({ path: "/bdsetting"});
    },
    goSelftTest(num){
      sessionStorage.setItem('setFrom','/bdx3micprog2advanced');
      if(num==1){
        this.$router.push({path:'/bdteststart'});
      }else{
        this.$router.push({path:'/bdtestresult'});
      }
    },
    factModeConfirm(value, i) {
      this.showPowerFact = false;
      this.LocalArr.factMode = value.text;
      this.factModeCode = value.code;
    },
    fixedTwo1(val){
      return this.comm.fixedTwo(val,0.8,1);
    },
    fixedTwo2(val) {
      return this.comm.fixedTwo(val, 0.9, 1);
    },
    fixedTwo3(val) {
      return this.comm.fixedTwo(val, 0, 1);
    },
    async getData() {
      this.comm.loadingShow();
      let datas = await this.SETAPI.LocalIn({'optType':'ReadSetData','pwd':sessionStorage.getItem('bdPwd')});
      if (datas!=null||datas!=undefined) {
        let dataArr = datas;
        this.safety = dataArr[0];
        sessionStorage.setItem("safety", this.safety);
        this.factModeCode = this.comm.bit8low(1,dataArr[3]);
        this.LocalArr.factMode = this.factorArr[this.factModeCode].text;
        /*判断用户的选择*/
        if (this.comm.bit8low(1,dataArr[3]) == 3) {
          this.isPFP = true;
        } else {
          this.isPFP = false;
        }
        if (this.comm.bit8low(1,dataArr[3]) == 4) {
          this.isQu = true;
        } else {
          this.isQu = false;
        }
        if (this.comm.bit8low(1,dataArr[3]) == 5) {
          this.isQSet = true;
        } else {
          this.isQSet = false;
        }
        this.LocalArr.P2Value = (this.comm.bit8high(1,dataArr[3]))/100;
        this.LocalArr.P3Value = (this.comm.bit8low(1,dataArr[4]))/100;
        this.LocalArr.P4Value = (this.comm.bit8high(1,dataArr[4]))/100;
        this.LocalArr.P5Value = (this.comm.bit8low(1,dataArr[92]))/100;
        this.LocalArr.P6Value = (this.comm.bit8high(1,dataArr[92]))/100;
        this.LocalArr.PowerRatio3Value=dataArr[95]/10;
        this.LocalArr.PowerRatio4Value=dataArr[96]/10;
        this.LocalArr.PfLockInPointValue = dataArr[17]/10;
        this.LocalArr.PfLockOutPointValue = dataArr[18]/10;
        this.LocalArr.bQpower_setValue = dataArr[58];
        this.LocalArr.VacMaxValue = dataArr[30]/10;
        this.LocalArr.VacMaxSlowProtectValue = dataArr[31]/10;
        this.LocalArr.VacMinValue = dataArr[33]/10;
        this.LocalArr.VacMinSlowProtectValue = dataArr[34]/10;
        this.LocalArr.OV10EnableValue = dataArr[36];
        this.LocalArr.Grid10MinAverageValue = dataArr[37]/10;
        this.LocalArr.FacMaxValue = dataArr[38]/100;
        this.LocalArr.FacMaxSlowProtectValue = dataArr[39]/100;
        this.LocalArr.FacMinValue = dataArr[40]/100;
        this.LocalArr.FacMinSlowProtectValue = dataArr[41]/100;
        this.LocalArr.FreqROCOFValue = dataArr[42];
        this.LocalArr.VacMiddleSlowProtectValue = dataArr[32]/10;
        this.LocalArr.TStartValue = dataArr[46];
        this.LocalArr.HLVRTFunctionValue = dataArr[43];
        /*判断用户的选择*/
        if (dataArr[43] == 1) {
          this.isHLVRT = true;
        } else {
          this.isHLVRT = false;
        }
        this.LocalArr.exportEnableCode = dataArr[29];
        /*判断用户的选择*/
        if (dataArr[29] == 1) {
          this.isExportControl = true;
        } else {
          this.isExportControl = false;
        }
        this.LocalArr.ExportLimitValue = dataArr[7];
        this.LocalArr.DRMFunctionValue = dataArr[63];
        this.LocalArr.puFunctionEnableCode = dataArr[55];
        /*判断用户的选择*/
        if (this.LocalArr.puFunctionEnableCode == 1) {
          this.isPu = true;
        } else {
          this.isPu = false;
        }
        this.LocalArr.SetV2Value = dataArr[82]/10;
        this.LocalArr.SetV3Value = dataArr[83]/10;
        this.LocalArr.SetV4Value = dataArr[84]/10;
        this.LocalArr.wFreqSetPointValue = dataArr[48]/100;
        this.LocalArr.wFreqDroopRateValue = dataArr[49]/10;
        this.LocalArr.softStartEnableCode = dataArr[53];
        /*判断用户的选择*/
        if (this.LocalArr.softStartEnableCode == 1) {
          this.isSoftStart = true;
        } else {
          this.isSoftStart = false;
        }
        this.LocalArr.InverterStartStopValue = dataArr[64];
        this.LocalArr.RS485AddressValue=dataArr[62];
        this.LocalArr.MpptScanModeValue=dataArr[97];
        this.LocalArr.POverfreqCode=dataArr[47];
        /*判断用户的选择*/
        if (this.LocalArr.POverfreqCode == 1) {
          this.isPOverfreq = true;
        } else {
          this.isPOverfreq = false;
        }
        this.LocalArr.CurveTypeValue=dataArr[76];
        /*判断用户的选择*/
        if(this.LocalArr.CurveTypeValue==2){
          this.isCurveType=true;
        }else{
          this.isCurveType=false;
        }
        this.LocalArr.EntryDelayTimeValue=dataArr[77]/100;
        this.LocalArr.ExitDelayTimeValue=dataArr[78]/100;
        this.LocalArr.FreqStopPointValue=dataArr[79]/100;
        this.LocalArr.PUnderfreqCode=dataArr[50];
        /*判断用户的选择*/
        if (this.LocalArr.PUnderfreqCode == 1) {
          this.isPUnderfreq = true;
        } else {
          this.isPUnderfreq = false;
        }
        this.LocalArr.FreqUnderPointValue=dataArr[51]/100;
        this.LocalArr.FreqUnderRampValue=dataArr[52]/10;
        this.LocalArr.IPBFEntryDelayTimeValue=dataArr[80]/100;
        this.LocalArr.SoftStartSlopeValue=dataArr[54]/10;
        this.LocalArr.QPowerLockEnValue=dataArr[85];
        this.LocalArr.QuLockInValue=dataArr[86]/10;
        this.LocalArr.QuLockOutValue=dataArr[87]/10;
        this.LocalArr.QuGridV1Value=dataArr[88]/10;
        this.LocalArr.QuGridV2Value=dataArr[89]/10;
        this.LocalArr.QuGridV3Value=dataArr[90]/10;
        this.LocalArr.QuGridV4Value=dataArr[91]/10;
        this.LocalArr.SetV1Value=dataArr[81]/10;
        this.LocalArr.ActivePowerLimitValue=dataArr[59];
        this.LocalArr.UVStage3Value=dataArr[35]/10;
        this.LocalArr.Frt_EntryVoltUpValue=dataArr[44]/10;
        this.LocalArr.Frt_EntryVoltDnValue=dataArr[45]/10;
        this.LocalArr.Qu_3TauValue=dataArr[56];
        this.LocalArr.Pu_3TauValue=dataArr[57];
        this.LocalArr.VacOvp1stTimeValue=dataArr[68]/100;
        this.LocalArr.VacOvp2ndTimeValue=dataArr[69]/100;
        this.LocalArr.VacUvp1stTimeValue=dataArr[70]/100;
        this.LocalArr.VacUvp2ndTimeValue=dataArr[71]/100;
        this.LocalArr.FacOfp1stTimeValue=dataArr[72]/100;
        this.LocalArr.FacOfp2ndTimeValue=dataArr[73]/100;
        this.LocalArr.FacUfp1stTimeValue=dataArr[74]/100;
        this.LocalArr.FacUfp2ndTimeValue=dataArr[75]/100;
        this.LocalArr.PowerRatio1Value=dataArr[93]/10;
        this.LocalArr.PowerRatio2Value=dataArr[94]/10;
        this.LocalArr.NewPasswordValue = this.comm.showPwd(dataArr[60]);
      } else {
        this.comm.tipsShow("InvNoResponse");
      }
    },
    //获取powerfactor列表
    getPowerFactory() {
      this.powerFactors = [{ text: this.$t('Off'), code: 0 },{ text: this.$t('OverExcited'), code: 1 },{ text: this.$t('UnderExcited'), code: 2 },{ text: this.$t('PF(P)2'), code: 3 },{ text: this.$t('Q(u)'), code: 4 },{ text: this.$t('Q-Set'), code: 5 }];
    },
    //设置安规
    setSafety(data){
      if(data=='success'){
        this.safety=sessionStorage.getItem('safety');
        this.getPowerFactory();
      }
    },
    //设置powerfactor
    async powerfactorSubmit() {
      //处理数据
      let factorData_new={};
      factorData_new.P1Value=this.factModeCode;
      if(this.LocalArr.P2Value!=null&&this.LocalArr.P2Value!=undefined){
        factorData_new.P2Value=this.comm.mulFunction(this.LocalArr.P2Value,100);
      }
      if(this.LocalArr.P3Value!=null&&this.LocalArr.P3Value!=undefined){
        factorData_new.P3Value=this.comm.mulFunction(this.LocalArr.P3Value,100);
      }
      if(this.LocalArr.P4Value!=null&&this.LocalArr.P4Value!=undefined){
        factorData_new.P4Value=this.comm.mulFunction(this.LocalArr.P4Value,100);
      }
      if(this.LocalArr.P5Value!=null&&this.LocalArr.P5Value!=undefined){
        factorData_new.P5Value=this.comm.mulFunction(this.LocalArr.P5Value,100);
      }
      if(this.LocalArr.P6Value!=null&&this.LocalArr.P6Value!=undefined){
        factorData_new.P6Value=this.comm.mulFunction(this.LocalArr.P6Value,100);
      }
      let Datas={
        'num':3,
        'Data':[
          {'reg':8,'val':((factorData_new.P2Value)*256+Number(factorData_new.P1Value))+''},
          {'reg':9,'val':((factorData_new.P4Value)*256+Number(factorData_new.P3Value))+''},
          {'reg':91,'val':((factorData_new.P6Value)*256+Number(factorData_new.P5Value))+''}
        ]
      };
      let params={
        'optType':"setReg",
        'Data':JSON.stringify(Datas),
        'pwd':sessionStorage.getItem('bdPwd')
      };
      this.comm.loadingShow();
      let data = await this.SETAPI.LocalIn(params);
      let newdata = data.substring(0,1);
      if (newdata == "Y") {
        this.comm.toastSuccess();
        /*判断用户的选择*/
        if (this.factModeCode == 3) {
          this.isPFP = true;
        } else {
          this.isPFP = false;
        }
        if (this.factModeCode == 4) {
          this.isQu = true;
        } else {
          this.isQu = false;
        }
        if (this.factModeCode == 5) {
          this.isQSet = true;
        } else {
          this.isQSet = false;
        }
      } else {
        this.comm.toastFail();
      }
    },
    //设置Export Enable
    setExportEnable(data) {
      /*判断用户的选择*/
      if (data == 1) {
        this.isExportControl = true;
      } else {
        this.isExportControl = false;
      }
    },
    //设置PU Function
    setPuFunction(data) {
      /*判断用户的选择*/
      if (data == 1) {
        this.isPu = true;
      } else {
        this.isPu = false;
      }
    },
    //设置SoftStart
    setSoftStart(data) {
      /*判断用户的选择*/
      if (data == 1) {
        this.isSoftStart = true;
      } else {
        this.isSoftStart = false;
      }
    },
    //设置POverfreqEnable
    setPOverfreqEnable(data){
      /*判断用户的选择*/
      if (data == 1) {
        this.isPOverfreq = true;
      } else {
        this.isPOverfreq = false;
      }
    },
    //设置PUnderfreqEnable
    setPUnderfreqEnable(data){
      /*判断用户的选择*/
      if (data == 1) {
        this.isPUnderfreq = true;
      } else {
        this.isPUnderfreq = false;
      }
    },
    //设置HLVRTFunction
    setHLVRTFunction(data){
      /*判断用户的选择*/
      if (data == 1) {
        this.isHLVRT = true;
      } else {
        this.isHLVRT = false;
      }
    },
    //设置CurveType
    setCurveType(data){
      /*判断用户的选择*/
      if (data == 2) {
        this. isCurveType = true;
      } else {
        this. isCurveType = false;
      }
    },
    onRefresh() {
      this.isLoading = false;
      this.timer = new Date().getTime();
      for (let i in this.LocalArr) {
        this.LocalArr[i] = "";
      }
      this.getData();
      this.getPowerFactory();
    },
  },
  mounted() {
    setTimeout(()=>{
      this.getData();
      this.getPowerFactory();
    },1000);
  },
};
</script>

<style scoped lang="less">
</style>
